//
//  main.cpp
//  CPlusPlus设计模式
//
//  Created by ZJ on 2018/7/23.
//  Copyright © 2018年 iCatch Technology Inc. All rights reserved.
//

#include <iostream>

using namespace std;

class Fruit {
    
public:
    virtual void getFruit()
    {
        cout << "Fruit::getFruit" << endl;
    }
};

class Pear : public Fruit {
    
public:
    virtual void getFruit()
    {
        cout << "Pear::getFruit" << endl;
    }
};

class Banana : public Fruit {
    
public:
    virtual void getFruit()
    {
        cout << "Banana::getFruit" << endl;
    }
};

// 工厂类
// 依赖
class Factory {
    
public:
    Fruit *Create(const char *name) {
        if (strcmp(name, "Pear") == 0) {
            return new Pear;
        } else if (strcmp(name, "Banana") == 0) {
            return new Banana;
        } else {
            return nullptr;
        }
    }
};

int main(int argc, const char * argv[]) {
    // insert code here...
    Factory *fa = nullptr;
    Fruit *fruit = nullptr;
    
    fa = new Factory;
    fruit = fa->Create("Pear");
    fruit->getFruit();
    
    delete fruit;
    
    //
    fruit = fa->Create("Banana");
    fruit->getFruit();
    
    delete fruit;
    
    std::cout << "Hello, World!\n";
    return 0;
}
